package com.hdax.dmw.order.api;

import com.hdax.dmw.dtos.order.TicketBuyerDto;
import com.hdax.dmw.order.service.DmOrderService;
import com.hdax.dmw.order.vo.SubmitOrderVo;
import com.hdax.dmw.utils.Result;
import com.hdax.dmw.utils.TokenUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping(path = "/order/p")
public class SubmitOrderApi {



    @PostMapping(path = "/submitorder")
    public Result<String> submitOrder(@RequestBody SubmitOrderVo vo,HttpServletRequest request){
        String token = request.getHeader("token");
        return orderService.submitOrder(vo,token);
    }

    @Autowired
    private DmOrderService orderService;
    @PostMapping(path = "/ticketbuyerlist")
    public Result<List<TicketBuyerDto>> ticketbuyerlist(HttpServletRequest request){
        String token = request.getHeader("token");
        Map<String, String> tokenMap = TokenUtil.parseToken(token);
        long userId = Long.parseLong(tokenMap.get("id"));
        return orderService.ticketBuyers(userId);
    }
}
